package com.moyu.common.core.utils;

import java.util.regex.Pattern;

/**
 * 邮箱验证工具类
 *
 * @Author 赵彦博
 * @Date 2025/3/25 20:58
 */
public class EmailValidationUtil {

    // 邮箱验证的正则表达式
    private static final String EMAIL_REGEX = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
    private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);

    /**
     * 验证邮箱地址是否合法
     * @param email 要验证的邮箱地址
     * @return 如果邮箱地址合法返回 true，否则返回 false
     */
    public static boolean isValidEmail(String email) {
        if (email == null) {
            return false;
        }
        return EMAIL_PATTERN.matcher(email).matches();
    }

}
